package com.vcms.utility.loader.storage.engine.file.impl;

import com.vcms.entity.store.item.DrinksStoreItem;
import com.vcms.entity.store.itemtype.DrinksBrand;
import com.vcms.exception.VMCSException;
import com.vcms.utility.loader.storage.engine.file.FileStorageEngine;

/**
 * @author robin.foe A0092657U
 * Bridge design pattern concrete implementor
 */
public class DrinkFileStorageEngine extends FileStorageEngine<DrinksStoreItem>{

	public static final String PROPERTY_NAME = "Name";
	public static final String PROPERTY_PRICE = "Price";
	public static final String PROPERTY_QUANTITY = "Quantity";
	
	public DrinkFileStorageEngine(String fileName) throws VMCSException {
		super(fileName);
	}
	
	@Override
	public DrinksStoreItem getItem(int pk) {
		DrinksBrand drinkBrand = new DrinksBrand();
		drinkBrand.setName(super.getValueFromProperty(PROPERTY_NAME + pk));
		drinkBrand.setPrice(Integer.parseInt(super.getValueFromProperty(PROPERTY_PRICE + pk)));
		return new DrinksStoreItem(drinkBrand, Integer.parseInt( super.getValueFromProperty(PROPERTY_QUANTITY + pk) ));
	}

	@Override
	public void setItem(int pk, DrinksStoreItem storeItem) {
		DrinksBrand drinkBrand = (DrinksBrand)storeItem.getContent();
		super.setValueToProperty(PROPERTY_NAME + pk, drinkBrand.getName());
		super.setValueToProperty(PROPERTY_PRICE + pk, String.valueOf(drinkBrand.getPrice()));
		super.setValueToProperty(PROPERTY_QUANTITY + pk, String.valueOf(storeItem.getQuantity()));
	}

}
